
import {
  CHANGEUSERNAME,
  CHANGEINPUTTEL2,
  CHANGEINPUTMA,
  CHANGEINPUTPASSWORD2,
  REGIST_200,
  CODE_200,
} from "../../actionType";
import axios from "../../../utils/myaxios";
const changeUserNameAction = (params) => ({
  type: CHANGEUSERNAME,
  params,
});
const changeTelAction = (params) => ({
  type: CHANGEINPUTTEL2,
  params,
});
const changeMaAction = (params) => ({
  type: CHANGEINPUTMA,
  params,
});
const changePwdAction = (params) => ({
  type: CHANGEINPUTPASSWORD2,
  params,
});
const handleRegistAction = (...value) => {
  // console.log(value);
  if(parseInt(value[2])===value[4]){
    return function (dispatch) {
      axios.post('user/regist',{userName:value[0],telephone:value[1],password:value[3]}).then(res=>{
        // console.log(res);
        if(res.code===200){
          dispatch({
            type:REGIST_200
          })
        }
      })
    };
  }else{
    return function (dispatch){
      dispatch({
        type:"",
        userInfo:{}
      })
    }
    
  }
  };
const getCodeAction2 =(val)=>{
  return function(dispatch){
    axios.post('/user/getSMSCode',{telephone:val,way:"regist"}).then(res=>{
      // console.log(res)
        dispatch({
          type:CODE_200,
          code1:res.code
        })
      
    })
  }
}
export {
  changeUserNameAction,
  changeTelAction,
  changeMaAction,
  changePwdAction,
  handleRegistAction,
  getCodeAction2,
};
